﻿using System.Web.Mvc;
using System.Web.Routing;
using Common;
using Common.WebApplication;
using Ninject;
using NinjectManager;

namespace EYCmsAdmin
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : BaseApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
            routes.IgnoreRoute("{*resource}", new { resource = @".*\.(js|css|png|gif|jpg|txt)(/.*)?" });

            routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = 0 }, new { id = @"\d+" });
        }

        protected override void Application_Start()
        {
            base.Application_Start();
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new RazorViewEngine());

            // Create Ninject DI kernel
            IKernel kernel = Ioc.Container;
            // set dependency injection
            ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());
            NinjectWebCommon.SetupDependencyInjection(kernel);
        }
    }
}